package game.objects;
import java.io.Serializable;
import java.util.TreeMap;

import tools.Help;
import tools.id.IdObject;
public class NameSystem<T extends IdObject> implements Serializable {
	private TreeMap<Integer, String> names;
	private TreeMap<String, Integer> fromNames;
	public NameSystem() {
		names = new TreeMap<Integer, String>();
		fromNames = new TreeMap<String, Integer>();
	}
	public void setName(T obj, String name) {
		names.put(obj.getId(), name);
		fromNames.put(name, obj.getId());
	}
	public String getName(T obj) {
		return names.get(obj.getId());
	}
	public String getName(int id) {
		return names.get(id);
	}
	public int getObjectId(String name) {
		assert (fromNames.containsKey(name)) : "An object with the name : " + name + " does not exist.";
		return fromNames.get(name);
	}
}
